package com.css.fxfzdzzh.modules.basicData.controller;

import com.alibaba.fastjson.JSONObject;
import com.css.fxfzdzzh.base.response.ResponseCode;
import com.css.fxfzdzzh.base.response.RestResponse;
import com.css.fxfzdzzh.modules.basicData.param.sysDataVersion.DataQueryParam;
import com.css.fxfzdzzh.modules.basicData.param.sysDataVersion.SysDataVersionPageParam;
import com.css.fxfzdzzh.modules.basicData.service.impl.BasicLandformService;
import io.swagger.annotations.Api;
import io.swagger.v3.oas.annotations.Operation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.*;

import java.util.Collections;

/**
 * @author Dbj
 * @date 2023年02月24日  16:08
 */
@Slf4j
@Api(tags = "数据管理")
@RestController
@RequestMapping("/basic")
public class BasicController {
    @Autowired
    private BasicLandformService sysDataVersionService;

    /**
     * dictCode :类别code 数据类别的dictItemCode
     * 水系 sx
     * 地形地貌 高程demgc
     * 活断层 hdc
     * 道路 dl
     * 地层岩性 dcyx
     * 地震动峰值加速度数据 pgakj
     * 气候qx
     */
    @Operation(summary = "类别树")
    @GetMapping("/typeTree")
    public RestResponse typeTree(@RequestParam String dictCode) {
        try {
            return sysDataVersionService.typeTree(dictCode);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return RestResponse.fail("查询失败!");
        }
    }

    @GetMapping("/getDataTypeLevel2AndDataTypeLevel3Tree")
    public RestResponse getDataTypeLevel2AndDataTypeLevel3Tree() {
        try {
            return sysDataVersionService.getDataTypeLevel2AndDataTypeLevel3Tree();
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return RestResponse.fail("查询失败!");
        }
    }

    @Operation(summary = "版本列表")
    @GetMapping("/versionList")
    public RestResponse versionList(SysDataVersionPageParam pageParam) {
        try {
            return sysDataVersionService.versionList(pageParam);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return RestResponse.fail("查询失败!");
        }
    }
    @Operation(summary = "版本列表")
    @GetMapping("/list")
    public RestResponse list(DataQueryParam pageParam) {
        try {
            return sysDataVersionService.list(pageParam);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return RestResponse.fail("查询失败!");
        }
    }


    /**
     * geomType:空间数据类型 0(点),1(线),2(面) 当dataCategory非道路时都填写空值表示查全部，当道路时填1
     * dataCategory:判断水系还是 底层岩性、地震动峰值加速度数据、气候、地形地貌、活断层、道路
     * probability：当dataCategory是地震动峰值加速度数据 对应的不同的数据 pga002 pga010 pga067
     */
    @Operation(summary = "根据数据版本查询数据")
    @GetMapping("/queryDataByVersionCode")
    public RestResponse queryDataByVersionCode(@RequestParam String dataCategory, String probability,String versionCode,String geomType, Integer page, Integer rows, @RequestHeader HttpHeaders headers) {
        try {
            return sysDataVersionService.queryDataByVersionCode(dataCategory,probability,versionCode,geomType,page,rows,headers);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return RestResponse.fail("查询失败!");
        }
    }
    @Operation(summary = "根据数据版本查询数据")
    @GetMapping("/queryByVersionCode")
    public RestResponse queryByVersionCode(@RequestParam String typeCode,String versionCode, Integer page, Integer rows, @RequestHeader HttpHeaders headers) {
        try {
            return sysDataVersionService.queryByVersionCode(typeCode,versionCode,page,rows,headers);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return RestResponse.fail("查询失败!");
        }
    }

    @Operation(summary = "根据数据版本不分页查询数据")
    @GetMapping("/queryAllByVersionCode")
    public RestResponse queryAllByVersionCode(@RequestParam String dataCategory, String probability,String versionCode,String geomType, @RequestHeader HttpHeaders headers) {
        try {
            return sysDataVersionService.queryAllByVersionCode(dataCategory,probability,versionCode,geomType,headers);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return RestResponse.fail("查询失败!");
        }
    }

    @GetMapping("/queryDataById")
    @Operation(summary = "根据id查询单条数据")
    public RestResponse queryDataById(String id, String typeCode, @RequestHeader HttpHeaders headers) {
        try {
            return sysDataVersionService.queryDataById(id,typeCode,headers);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return RestResponse.fail("查询失败!");
        }

    }
}
